package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("insertUser")
    public String add(){
        User user = new User();
        user.setName("张三2222");
        user.setAge(21);
        user.setAdderss("北京");
        user.setCreatetime(new Date());
        userService.insertUser(user);
        return "保存成功";
    }

    @RequestMapping("updateUser")
    public String update(){
        User user = new User();
        user.setId(1);
        user.setName("张三111");
        user.setAge(222);
        user.setAdderss("河北");
        user.setCreatetime(new Date());
        userService.updateUser(user);
        return "保存成功";
    }

    @RequestMapping("deleteUser")
    public String delete(){
        int id=1;
        userService.deleteUser(id);
        return "保存成功";
    }

    @RequestMapping("userSelect")
    public String select(){
        User user=new User();

        List<User> list=userService.userSelect(user);
        return ""+list;
    }
}
